var controllers = {};

controllers.UsersController = function ($scope, $http, $log) {	
	


	$scope.login = function() {
		

		// $http.defaults.headers.common.ContentType = 'application/x-www-form-urlencoded';
		$scope.url = config.apiUrl + config.resources.customers;
		// $scope.data = {
		// 	email: $('#hfr-login').val(),
		// };

		// alert($http.defaults.headers.common.ContentType);
		$scope.data = 'email=chomeo@chomeo.com';
		

		$http.post($scope.url, $scope.data, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).
		success(function(data, status, headers, config) {

	    	console.log(data);
	    }).
	    error(function(data, status, headers, config) {
	    	console.log("eeeee" + data);
	      // called asynchronously if an error occurs
	      // or server returns response with an error status.
	    });
	};


	$scope.googleLogin = function(){
		 $scope.$on('event:google-plus-signin-success', function (event, authResult) {
          // User successfully authorized the G+ App!
          console.log('Signed in!');
        });
        $scope.$on('event:google-plus-signin-failure', function (event, authResult) {
          // User has not authorized the G+ App!
          console.log('Not signed into Google Plus.');
        });
	};

	$scope.getCustomerInfo = function(){

		$scope.url = config.apiUrl + config.resources.customers + "/" + $('#hfr-cusName').val();
		
		$http.get($scope.url).
		success(function(data, status, headers, config) {
			$scope.customerApikey = data.response.customer.apiKey;
			$scope.customerCoint = data.response.customer.coint;
			$scope.customerCreated = data.response.customer.created;
			$scope.customerEmail = data.response.customer.email;			
			$scope.customerExpired = data.response.customer.expired;
			$scope.customerFirst = data.response.customer.first;
			$scope.customerLastUpdated = data.response.customer.lastUpdated;
			$scope.customerPrimaryKey = data.response.customer.primaryKey;
			$scope.customerRefer = data.response.customer.refer;
			$scope.customerSource = data.response.customer.source;
			$scope.customerSourceActive = data.response.customer.sourceActive;
			$scope.customerStatus = data.response.customer.status;
			$scope.customerType = data.response.customer.type;

	    	console.log(data);

	    }).
	    error(function(data, status, headers, config) {
	    	console.log("eeeee" + data);
	    });
	};
};

hfrApp.controller(controllers);